﻿@model IEnumerable<CmsUserGroup>

@{
    Layout = "~/admin/Templates/TelerikAdministration.cshtml";
    ResFile = "cms_Users";
}

@{
    ViewBag.Title = _("User groups");
}

<h1 class="g-clear">
	<i class="b-icon b-icon_h b-icon_h_users"></i>
	<span class="b-overflow">
	@_("Users Groups")
	<span class="b-intro-text">@_("The following table contains all user groups for this site.")</span>   
	</span>  
</h1>

<div id="TabStrip" class="t-widget t-tabstrip t-header">
	<ul class="t-reset t-tabstrip-items">
		<li class="t-item t-state-default">
			<a href="/admin/cmsuser" class="t-link">@_("Users")</a>			
		</li>
		<li class="t-item t-state-active">
			<a href="/admin/cmsusergroup" class="t-link">@_("User groups")</a>			
		</li>
		<li class="t-item t-state-default">
			<a href="/admin/cmsusermetafield" class="t-link">@_("User Metas")</a>			
		</li>		
	</ul>
	<div style="display: block;" id="TabStrip-1" class="t-content t-state-active">
		<div class="t-content-inner g-clear">
			<p class="clear-left">
			    <a class="b-button b-button_save" href="@Url.Action("add", "cmsusergroup")">@_("Add new user group")</a>
			</p>
			@{Html.RenderPartial("ErrorPanel");}
			@(Html.Telerik().Grid(Model).Name("UserGroupGrid")
			        .Columns(columns =>
			        {
			            columns.Bound(p => p.GroupName).Title(_("Group name")).Template(
			                @<text>
			                <a href="@Url.Action("edit", "cmsusergroup", new { id = item.Id })">@item.GroupName</a>
			                </text>
			            ).ClientTemplate("<a href=" + Url.Action("edit", "cmsusergroup") + "/<#= Id#>><#= GroupName#></a>");
			            columns.Bound(p => p.IsEnabled).Title(_("Is enbaled")).ClientTemplate("<input type='checkbox' name='IsEnabled' <#= IsEnabled? checked='checked' : '' #> disabled />");
			            columns.Bound(p => p.IsSystem).Title(_("Is system")).ClientTemplate("<input type='checkbox' name='IsSystem' <#= IsSystem? checked='checked' : '' #> disabled />");
			            columns.Bound(p => p.DateCreated).Title(_("Date created")).Format("{0:dd/MM/yyyy}").ClientTemplate("<#= $.telerik.formatString('{0:dd/MM/yyyy}', DateCreated) #>");
			            columns.Bound(p => p.Id);
			            columns.Template(
			                @<text>
			                @if (!item.IsSystem)
			                {                    
			                    <a class="b-icon b-icon_delete" title="@_("Delete")" href="@Url.Action("delete", "cmsusergroup", new { id = item.Id })">@_("Delete")</a>
			                }
			                </text>
			            )
			            .ClientTemplate("<a id='usergroup-delete-<#= Id #>' class='b-icon b-icon_delete' title='"+_("Delete")+"'>"+_("Delete")+"</a>")
			            .Title(_("Delete"));
			        })
			        .DataBinding(dataBinding =>
			        {
			            dataBinding.Ajax().Select("_Index", "CmsUserGroup");
			        })
			        .ClientEvents(events => events.OnRowDataBound("grid_onRowDataBound"))
			        .Scrollable(scrolling => scrolling.Enabled(false))
			        .Sortable(sorting => sorting.Enabled(true))
			        .Pageable(paging => paging.Style(GridPagerStyles.Numeric).Total(ViewBag.Total).PageSize(ViewBag.PageSize).Enabled(ViewBag.Total > ViewBag.PageSize))
			)
			@{Html.RenderPartial("GridSizer", (int)ViewBag.PageSize);}
		</div>
	</div>
</div>

@section scriptBlock{
<script type="text/javascript">
// <![CDATA[
    function grid_onRowDataBound(e) {
        var dataItem = e.dataItem
        var $el = $('#usergroup-delete-' + dataItem.Id);
        if ($el) {
            if (!dataItem.IsSystem) {
                $el.attr('href', '@Url.Action("delete", "cmsusergroup")' + "/" + dataItem.Id);
            }
            else {
                $el.hide().remove();
            }
        }
    }
    // ]]>
</script>
}